package com.qys.livesMall.shortVideo.controller.app;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qys.livesMall.common.result.R;
import com.qys.livesMall.shortVideo.model.dto.app.AppShortVideoCommentQueryDTO;
import com.qys.livesMall.shortVideo.model.dto.app.AppUserCommentDTO;
import com.qys.livesMall.shortVideo.model.vo.app.AppShortVideoCommentVO;
import com.qys.livesMall.shortVideo.service.IH2ShortVideoCommentsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 短视频评论 前端控制器
 * </p>
 *
 * @author dp
 * @since 2023-05-04
 */
@RestController
@RequestMapping("/app/short/video/comments")
@Tag(name = "App-短视频评论信息", description = "App-短视频评论信息")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class AppShortVideoCommentsController {

    private final IH2ShortVideoCommentsService shortVideoCommentsService;

    @PostMapping
    @Operation(summary = "用户评论视频信息")
    public R<String> comment(@RequestBody AppUserCommentDTO commentDTO) {
        return R.ok(shortVideoCommentsService.comment(commentDTO));
    }

    @PostMapping("/page")
    @Operation(summary = "查看短视频信息")
    public R<Page<AppShortVideoCommentVO>> page(@RequestBody AppShortVideoCommentQueryDTO queryDTO) {
        if (StringUtils.isNotBlank(queryDTO.getParentId())) queryDTO.setId(null);
        return R.ok(shortVideoCommentsService.pageByApp(queryDTO));
    }

    @PutMapping("/like/{id}/{type}")
    @Operation(summary = "点赞短视频评论信息")
    @Parameters({
            @Parameter(name = "id", description = "id"),
            @Parameter(name = "type", description = "类型(0点赞/1取消)"),
    })
    public R<?> like(@PathVariable String id, @PathVariable byte type) {
        return R.ok(shortVideoCommentsService.like(id, type));
    }

    @PutMapping("/dislike/{id}/{type}")
    @Operation(summary = "不喜欢短视频评论信息")
    @Parameters({
            @Parameter(name = "id", description = "id"),
            @Parameter(name = "type", description = "类型(0不喜欢/1取消)"),
    })
    public R<Page<AppShortVideoCommentVO>> dislike(@PathVariable String id, @PathVariable byte type) {
        shortVideoCommentsService.dislike(id, type);
        return R.ok();
    }
}
